package com.wj.controller;

import com.wj.common.TableId;
import com.wj.goods.DeductGoodsInventory;
import com.wj.goods.GoodsInfo;
import com.wj.goods.SimpleGoodsInfo;
import com.wj.service.IGoodsService;
import com.wj.vo.PageSimpleGoodsInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品微服务功能接口")
@Slf4j
@RestController
@RequestMapping("/")
public class GoodsController {

    private final IGoodsService goodsService;

    public GoodsController(IGoodsService goodsService) {
        this.goodsService = goodsService;
    }

    @ApiOperation(value = "详情商品信息", notes = "根据 TableId 查询详情商品信息", httpMethod = "POST")
    @PostMapping("/goods-info")
    public List<GoodsInfo> getGoodsInfoByTableId(@RequestBody TableId tableId){
        return goodsService.getGoodsInfoByTableId(tableId);
    }


    @ApiOperation(value = "简单商品信息", notes = "获取分页的简单商品信息", httpMethod = "POST")
    @PostMapping("/page-simple-goods-info")
    public PageSimpleGoodsInfo getSimpleGoodsInfoByPage(@RequestParam(required = false, defaultValue = "1") int page){
        return goodsService.getSimpleGoodsInfoByPage(page);
    }


    @ApiOperation(value = "简单商品信息", notes = "根据 TableId 查询简单商品信息", httpMethod = "POST")
    @PostMapping("/simple-goods-info")
    public List<SimpleGoodsInfo> getSimpleGoodsInfoByTableId(@RequestBody TableId tableId){
        return goodsService.getSimpleGoodsInfoByTableId(tableId);
    }

    @ApiOperation(value = "扣减商品库存", notes = "扣减商品库存", httpMethod = "POST")
    @PostMapping("/deduct-goods-inventory")
    public List<DeductGoodsInventory> deductGoodsInventories (@RequestBody List<DeductGoodsInventory> deductGoodsInventories){
        return goodsService.deductGoodsInventories(deductGoodsInventories);
    }
}
